package com.cfs.svcimpl.bz;

import java.util.List;

import com.cfs.dao.bz.TvboxDao;
import com.cfs.po.bz.Tvbox;
import com.cfs.svc.bz.TvboxService;
import com.cfs.vo.Condition;
import com.cfs.vo.Pager;
import com.cfs.vo.Res;

public class TvboxServiceImpl implements TvboxService {

	private TvboxDao dao;

	public TvboxDao getDao() {
		return dao;
	}

	public void setDao(TvboxDao dao) {
		this.dao = dao;
	}

	@Override
	public Long addTvbox(Tvbox t) {
		Long n = dao.insert(t);
		return t.getId();
	}

	@Override
	public int deleteById(Long id) {
		return dao.delete(id);
	}

	@Override
	public Long updateTvbox(Tvbox t) {
		Long n = dao.update(t);
		return t.getId();
	}

	@Override
	public List<Tvbox> list(Condition c) {
		return dao.list(c);
	}

	@Override
	public Res<Tvbox> listP(Condition c) {

		Res<Tvbox> res = new Res<Tvbox>();
		try{
			Pager p = c.getP() == null ? new Pager() : c.getP();
			p.resetTotalR(dao.queryRows(c));
			List<Tvbox> list = dao.list(c);

			res.setP(p);
			res.setList(list);

		}catch(Exception e){
			res.setCode(-1);
			res.setMsg(e.getLocalizedMessage());
			e.printStackTrace();
		}

		return res;
	}

	@Override
	public Tvbox get(Long id) {
		return dao.get(id);
	}

}
